package com.tywj.lib.core.common.extension

import android.app.Activity
import android.os.Build
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : Activity扩展
 *     version: 1.0.0
 * </pre>
*/

/**
 * Activity 是否被销毁
 */
fun Activity.isActivityDestroyed(): Boolean {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (isFinishing || isDestroyed) {
            return true
        }
    } else {
        if (isFinishing) {
            return true
        }
    }

    return false
}

/**
 * Activity 是否被销毁
 */
fun AppCompatActivity.isActivityDestroyed(): Boolean {
    return lifecycle.currentState == Lifecycle.State.DESTROYED
}

fun Activity.gone(vararg arr: View) {
    arr.forEach {
        if (it.visibility != View.GONE) {
            it.visibility = View.GONE
        }
    }
}

fun Activity.visible(vararg arr: View) {
    arr.forEach {
        if (it.visibility != View.VISIBLE) {
            it.visibility = View.VISIBLE
        }
    }
}

fun Activity.invisible(vararg arr: View) {
    arr.forEach {
        if (it.visibility != View.INVISIBLE) {
            it.visibility = View.INVISIBLE
        }
    }
}